package com.tobby.camel.camelinaction.chapter3.order;

import org.apache.camel.Header;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class PurchaseOrderJSONSpringTest extends CamelSpringTestSupport {

	private static Logger LOG = LoggerFactory
			.getLogger(PurchaseOrderJSONSpringTest.class);

	@Override
	protected AbstractApplicationContext createApplicationContext() {
		return new ClassPathXmlApplicationContext(
				"com/tobby/camel/camelinaction/chapter3/order/order-json.xml");
	}

	@Test
	public void testJson() throws InterruptedException {
		String out = template.requestBody("http://localhost:8080/order/service?id=123",
				null, String.class);
		LOG.info("Response form order Service : " + out);

		assertNotNull(out);
		assertTrue(out.contains("Camel in Action"));
	}

	public static class OrderServiceBean {
		public PurchaseOrder lookup(@Header("id") String id) {
			LOG.info("Finding purchase order for " + id);
			return new PurchaseOrder("Camel in Action", 49.95, 1);
		}
	}

}
